package CSCE428;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Vector;

public class Match {
	
	String RegExpression;
	public Match(){
		RegExpression="";
	}
	public boolean MatchRegressionExpression(ArrayDeque<NFAState> DFAQueue, String input, ArrayList<Character> InputSet){
		RegExpression=input;

		if(RegExpression.length()==1 && RegExpression.charAt(0)=='e')
			return DFAQueue.getFirst().AcceptingState? true: false;

		if(DFAQueue.isEmpty())//if there is nothing return false
			return false;

		Iterator iter=DFAQueue.iterator();
		NFAState NextState = (NFAState)iter.next();//Traverse from the start state
		for(int i=0; i<RegExpression.length(); i++)
		{
			char ch = RegExpression.charAt(i);
			if(!InputSet.contains(ch)){
				System.out.print("Wrong Vocabulary!");
				return false;
			}
			Vector<NFAState> Transition=NextState.GetTransition(ch);
			if(!Transition.isEmpty())
				NextState = Transition.elementAt(0);//at most one state corresponding to one input char, so the index is only 0
		}
		
		if(NextState.AcceptingState)
			return true;
		
		return false;
	}
}
